<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateLessonResourcesTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create($this->tableName, function(Blueprint $table){
			$table->increments('id')->comment('主键id');

			$table->string('origin_name', 60)->comment('用户上传时的文件名');
			$table->string('mime', 40)->nullable()->comment('文件的MIME格式');
			$table->string('ext_name', 60)->comment('文件扩展名');
			$table->string('real_name', 60)->comment('文件储存时的文件名');

			$table->unsignedInteger('lesson_id')->comment('所属于的课程');
			$table->foreign('lesson_id')->references('id')->on('lessons')->onDelete('cascade');
			$table->unsignedInteger('creater_id')->comment('创建者的用户id');
			$table->foreign('creater_id')->references('id')->on('users')->onDelete('cascade');

			$table->boolean('from_teacher');

			$table->timestamps();
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop($this->tableName);
	}

	private $tableName = 'lesson_resources';
}
